Skip to content

[X86] Support EVEX compression for EGPR #77202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

KanRobert
Copy link
Contributor

@KanRobert KanRobert commented Jan 6, 2024

Compress promoted instruction (EVEX) to pre-promotion instruction (legacy/VEX) when R16-R31 is not used.

Alternative of #77065

@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2024

@llvm/pr-subscribers-backend-x86

Author: Shengchen Kan (KanRobert)

Changes

Promoted instruction (EVEX) -> pre-promotion instruction (legacy/VEX)


Full diff: https://github.com/llvm/llvm-project/pull/77202.diff

1 Files Affected:

  • (modified) llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp (+6-2)
diff --git a/llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp b/llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp
index b03bcb6bc26b30..c519c07b243c24 100644
--- a/llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp
+++ b/llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp
@@ -167,12 +167,16 @@ void X86CompressEVEXTablesEmitter::run(raw_ostream &OS) {
   for (const CodeGenInstruction *Inst : PreCompressionInsts) {
     const Record *Rec = Inst->TheDef;
     uint8_t Opcode =
-        byteFromBitsInit(Inst->TheDef->getValueAsBitsInit("Opcode"));
+        byteFromBitsInit(Rec->getValueAsBitsInit("Opcode"));
+    StringRef Name = Rec->getName();
     const CodeGenInstruction *NewInst = nullptr;
-    if (ManualMap.find(Rec->getName()) != ManualMap.end()) {
+    if (ManualMap.find(Name) != ManualMap.end()) {
       Record *NewRec = Records.getDef(ManualMap.at(Rec->getName()));
       assert(NewRec && "Instruction not found!");
       NewInst = &Target.getInstruction(NewRec);
+    } else if (Name.ends_with("_EVEX")) {
+      if (auto *NewRec = Records.getDef(Name.drop_back(5)))
+        NewInst = &Target.getInstruction(NewRec);
     } else {
       // For each pre-compression instruction look for a match in the appropriate
       // vector (instructions with the same opcode) using function object

@KanRobert KanRobert marked this pull request as draft January 6, 2024 16:13
Copy link

github-actions bot commented Jan 6, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@KanRobert KanRobert marked this pull request as ready for review January 7, 2024 02:04
@KanRobert KanRobert changed the title [X86] Support 2nd EVEX compression described in X86CompressEVEX.cpp [X86] Support compression promoted instruction (EVEX) -> pre-promotion instruction (legacy/VEX) Jan 7, 2024
@KanRobert KanRobert changed the title [X86] Support compression promoted instruction (EVEX) -> pre-promotion instruction (legacy/VEX) [X86] Support EVEX compression for EGPR Jan 7, 2024
@@ -29,8 +29,10 @@ class X86Subtarget;
namespace X86 {

enum AsmComments {
// For instr that was compressed from EVEX to LEGACY.
AC_EVEX_2_LEGACY = MachineInstr::TAsmComments,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need to associate with this value? Will it be a problem if there's new Flag added after MachineInstr::TAsmComments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  enum CommentFlag {
    ReloadReuse = 0x1,    // higher bits are reserved for target dep comments.
    NoSchedComment = 0x2,
    TAsmComments = 0x4    // Target Asm comments should start from this value.
  };

It's documented at llvm/include/llvm/CodeGen/MachineInstr.h. T is short for target and TAsmComments should always be the last value here.

Copy link
Contributor

@XinWang10 XinWang10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@KanRobert
Copy link
Contributor Author

Thanks @XinWang10 !

@KanRobert KanRobert merged commit 1c67466 into llvm:main Jan 8, 2024
KanRobert added a commit that referenced this pull request Jan 8, 2024
This patch is a straightfoward change based on the design in #77202.
It does not have any effect since we haven't supported compressing ND
to non-ND in X86CompressEVEX.cpp.
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
Compress promoted instruction (EVEX) to pre-promotion instruction
(legacy/VEX) when R16-R31 is not used.

Alternative of llvm#77065
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
This patch is a straightfoward change based on the design in llvm#77202.
It does not have any effect since we haven't supported compressing ND
to non-ND in X86CompressEVEX.cpp.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants